//
//  SmsCloudTableCell.m

#import "SmsCloudTableCell.h"

static NSString * SmsCloudTableCellId = @"SmsCloudTableCellId";
@interface SmsCloudTableCell()
@property (nonatomic,strong) UIImageView *smsCloudHeadImgView;
@property (nonatomic,strong) UILabel *smsCloudHeadIndexLab;
@property (nonatomic,strong) UIImageView *smsCloudImgView;
@property (nonatomic,strong) UILabel *smsCloudHeadNameLab;
@property (nonatomic,strong) UILabel *smsCloudHeadNumLab;
@end
@implementation SmsCloudTableCell
+ (instancetype)smsCloudTableCell:(UITableView *)tableView{
    SmsCloudTableCell * smsCloudTableCell = [tableView dequeueReusableCellWithIdentifier:SmsCloudTableCellId];
    if (!smsCloudTableCell) {
        smsCloudTableCell = [[SmsCloudTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SmsCloudTableCellId];
    }
    smsCloudTableCell.backgroundColor = [UIColor clearColor];
    smsCloudTableCell.selectionStyle = UITableViewCellSelectionStyleNone;
    smsCloudTableCell.accessoryType = UITableViewCellAccessoryNone;
    return smsCloudTableCell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self smsCloudInitView];
    }
    return self;
}
- (void)smsCloudInitView{
    self.smsCloudHeadImgView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.smsCloudHeadImgView];
    [self.smsCloudHeadImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([SmsCloudHead SmsCloudScreewRatio:19]));
        make.centerY.equalTo(self);
        make.width.equalTo(@([SmsCloudHead SmsCloudScreewRatio:68]));
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:68]));
    }];
    self.smsCloudHeadIndexLab = [[UILabel alloc] init];
    self.smsCloudHeadIndexLab.font = [UIFont systemFontOfSize:[SmsCloudHead SmsCloudScreewRatio:29] weight:UIFontWeightBold];
    self.smsCloudHeadIndexLab.textColor = [SmsCloudHead SmsCloudColorHexString:@"#FFFFFF"];
    self.smsCloudHeadIndexLab.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.smsCloudHeadIndexLab];
    [self.smsCloudHeadIndexLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.smsCloudHeadImgView).offset([SmsCloudHead SmsCloudScreewRatio:5]);
        make.centerX.equalTo(self.smsCloudHeadImgView);
    }];
    self.smsCloudImgView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.smsCloudImgView];
    [self.smsCloudImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.smsCloudHeadImgView.mas_right).offset([SmsCloudHead SmsCloudScreewRatio:24]);
        make.centerY.equalTo(self);
        make.width.equalTo(@([SmsCloudHead SmsCloudScreewRatio:88]));
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:88]));
    }];
    self.smsCloudHeadNameLab = [[UILabel alloc] init];
    self.smsCloudHeadNameLab.font = [UIFont systemFontOfSize:[SmsCloudHead SmsCloudScreewRatio:30] weight:UIFontWeightRegular];
    self.smsCloudHeadNameLab.textColor = [SmsCloudHead SmsCloudColorHexString:@"#262729"];
    [self.contentView addSubview:self.smsCloudHeadNameLab];
    [self.smsCloudHeadNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.smsCloudImgView.mas_right).offset([SmsCloudHead SmsCloudScreewRatio:19]);
        make.top.equalTo(self.smsCloudImgView).offset([SmsCloudHead SmsCloudScreewRatio:3]);
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:42]));
    }];
    self.smsCloudHeadNumLab = [[UILabel alloc] init];
    self.smsCloudHeadNumLab.font = [UIFont systemFontOfSize:[SmsCloudHead SmsCloudScreewRatio:24] weight:UIFontWeightMedium];
    self.smsCloudHeadNumLab.textColor = [SmsCloudHead SmsCloudColorHexString:@"#08C161"];
    [self.contentView addSubview:self.smsCloudHeadNumLab];
    [self.smsCloudHeadNumLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.smsCloudHeadNameLab);
        make.top.equalTo(self.smsCloudHeadNameLab.mas_bottom).offset([SmsCloudHead SmsCloudScreewRatio:6]);
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:34]));
    }];
    UIImageView * smsCloudGoImgView = [[UIImageView alloc] init];
    smsCloudGoImgView.image = [SmsCloudHead SmsCloudImageNamed:@"smsCloudHomeGo"];
    [self.contentView addSubview:smsCloudGoImgView];
    [smsCloudGoImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-[SmsCloudHead SmsCloudScreewRatio:24]));
        make.centerY.equalTo(self.contentView);
        make.width.equalTo(@([SmsCloudHead SmsCloudScreewRatio:198]));
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:66]));
    }];
    UIButton * smsCloudGobtn = [[UIButton alloc] init];
    [smsCloudGobtn addTarget:self action:@selector(smsCloudGo) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:smsCloudGobtn];
    [smsCloudGobtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
    }];
}
- (void)smsCloudGo{
    if(self.SmsCloudProductBlock){
        self.SmsCloudProductBlock(_smsCloudProductMdl);
    }
}
-(void)setSmsCloudProductMdl:(SmsCloudProductModel *)smsCloudProductMdl{
    _smsCloudProductMdl = smsCloudProductMdl;
    if(_smsCloudProductMdl){
        self.smsCloudHeadNameLab.text = _smsCloudProductMdl.name;
        [self.smsCloudImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://www.ydl.cool/img/static/sms/%@0.webp",_smsCloudProductMdl.code]] placeholderImage:[SmsCloudHead SmsCloudImageNamed:@"smsCloudLogo"]];
        self.smsCloudHeadNumLab.text = [NSString stringWithFormat:@"今日注册%@+",_smsCloudProductMdl.num];
    }
}
-(void)setSmsCloudIndex:(NSInteger)smsCloudIndex{
    _smsCloudIndex = smsCloudIndex;
    self.smsCloudHeadIndexLab.text = [NSString stringWithFormat:@"%zd",_smsCloudIndex];
    if (_smsCloudIndex == 1) {
        self.smsCloudHeadImgView.image = [SmsCloudHead SmsCloudImageNamed:@"smsCloudIndex_1"];
        self.smsCloudHeadIndexLab.hidden = true;
    }else if (_smsCloudIndex == 2){
        self.smsCloudHeadImgView.image = [SmsCloudHead SmsCloudImageNamed:@"smsCloudIndex_2"];
        self.smsCloudHeadIndexLab.hidden = false;
    }else if (_smsCloudIndex == 3){
        self.smsCloudHeadImgView.image = [SmsCloudHead SmsCloudImageNamed:@"smsCloudIndex_3"];
        self.smsCloudHeadIndexLab.hidden = true;
    }else{
        self.smsCloudHeadImgView.image = [SmsCloudHead SmsCloudImageNamed:@"smsCloudIndexNo"];
        self.smsCloudHeadIndexLab.hidden = false;
    }
}
@end
